class Solution {
public:
    int Ahappy(int a)
    {
        int sum=0;
        while(a>0)
        {
            sum=sum+(a%10)*(a%10);
            a/=10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow=n;
        int fast=Ahappy(n);
        while(slow!=fast)
        {
        slow=Ahappy(slow);
        fast=Ahappy(Ahappy(fast));
        }
        return slow==1?true:false;

        
    }
};
